package com.apes.fico.finance.respository;

import com.apes.fico.finance.model.statements.IncomeStatementFormula;
import com.apes.framework.jpa.repository.CustomRepository;
import org.springframework.data.jpa.repository.Query;

import java.util.List;
import java.util.Map;

public interface IncomeStatementFormulaRepository extends CustomRepository<IncomeStatementFormula, String> {
    @Query("select new map(T.id as id,T.code as code,T.orientation as orientation,T.incomeStatement.id as incomeStatement_id) from IncomeStatementFormula T where 1=1")
    List<Map<String,String>> findAllByIncomeStatementFormula();

    @Query(value = "SELECT a.*," +
            "       (SELECT to_char(REPLACE(wm_concat(operator || '#' || acc_code || '$'), ',', '')) " +
            "           FROM gl_income_statement_formula b " +
            "          WHERE a.id = b.income_id " +
            "          GROUP BY b.income_id) asschart " +
            "  FROM gl_income_statement a",nativeQuery = true)
    List<Map> findIncome();

}
